package week2;

public class StringTest1 {
    public String  trim(String str){
        if(str == null ||str.equals("")){
            return " ";
        }
        int start = 0;
        int end = str.length() - 1;
        while ((start <= end) && (str.charAt(start) == ' ')){
            start++;
        }
        while ((start <= end) && (str.charAt(end) == ' ')){
            end--;
        }
        return str.substring(start,end + 1) ;
    }

    public String toLowerCase(String str){
        char[] array = str.toCharArray();
        for (int i = 0; i < array.length; i++){
            if(array[i] >= 'A' && array[i] <= 'Z'){
                array[i] = (char)(array[i] + 32);
            }
        }
        return String.valueOf(array);
    }
    public String toUpperCase(String str){
        char[] array = str.toCharArray();
        for (int i = 0; i < array.length; i++){
            if(array[i] >= 'a' && array[i] <= 'z'){
                array[i] = (char)(array[i] - 32);
            }
        }
        return String.valueOf(array);
    }


}
